<?php
/**
 * Created by PhpStorm.
 * User: peter
 * Date: 2018/6/8
 * Time: 上午11:28
 */

namespace app\admin\controller;


use think\Request;

class Goods extends Auth
{
    /**
     * @purpose 添加商品
     * @param Request $request
     * @return array
     */
    public function create(Request $request) {
        $data = $request->post();
        return \app\admin\logic\Goods::create($data);
    }

    /**
     * @purpose 获取商品列表
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function items(Request $request) {
        $page   = $request->get('page', 1);
        $size   = $request->get('size', 50);
        $status = $request->get('status',0);
        $where  = [];
        $where['status'] = $status;
        return \app\admin\logic\Goods::items($where, $page, $size);
    }

    /**
     * @purpose 通过ID获取单条数据
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function infoById (Request $request)
    {
        $id     = $request->get('id');
        return \app\admin\logic\Goods::infoById($id);
    }

    /**
     * @purpose 编辑商品
     * @param Request $request
     * @return array
     * @throws \think\exception\PDOException
     */
    public function edit (Request $request)
    {
        $data   = $request->post();
        return \app\admin\logic\Goods::edit($data);
    }

    /**
     * @purpose 通过ID更新商品状态
     * @param Request $request
     */
    public function status (Request $request) {
        $id     = $request->post('id');
        $status = $request->post('status');
        return \app\admin\logic\Goods::status($id, $status);
    }
}